home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HPAVC
/
HPAVC CD-ROM.iso
/
P_ROBO31.ZIP
/
TAGTEAM2.PR
< prev
next >
Wrap
Text File
|
1989-10-23
|
5KB
|
144 lines
PROCEDURE TagTeam2;
TeamAlly = "TagTeam1";
{
Author: David Malmberg
Strategy: Go to a random corner, raise shield, and blast away at any
robot in range. Improve aim after every successful scan. If the
robot scans 20 times unsuccessfully, move to another random
corner. Lower shields when moving; raise them when stopped.
This robot can act individually or as part of a team with another
robot that follows an identical strategy, i.e., TagTeam2. If
operating as a team, the two robots communicate their corners
to each other by setting COMM[10] to TagTeam1's corner and
COMM[11] to TagTeam2's corner. They try to always pick different
random corners.
WARNING: This Robot has not been designed to deal with
Obstructions effectively.
}
CONST
NW_Corner = 1;
NE_Corner = 2;
SW_Corner = 3;
SE_Corner = 4;
VAR { TagTeam2 "Global" variables }
CornerX : ARRAY[1..4] OF Integer; {X coordinate of Corners}
CornerY : ARRAY[1..4] OF Integer; {Y coordinate of Corners}
StartAngle : ARRAY[1..4] OF Integer; {Starting scanning angles for Corners}
Corner, { Current Corner }
Times, { Number of times robot as scanned without success for enemy }
Angle, { Scanning angle }
Delta, { Scanning angle width }
Range { Range/Distance to foe } : Integer;
PROCEDURE Initialize;
BEGIN
CornerX[NW_Corner] := 10;
CornerY[NW_Corner] := 990;
StartAngle[NW_Corner] := 270;
CornerX[NE_Corner] := 990;
CornerY[NE_Corner] := 990;
StartAngle[NE_Corner] := 180;
CornerX[SW_Corner] := 10;
CornerY[SW_Corner] := 10;
StartAngle[SW_Corner] := 0;
CornerX[SE_Corner] := 990;
CornerY[SE_Corner] := 10;
StartAngle[SE_Corner] := 90;
END; {Initialize}
PROCEDURE GOTO(x, y : Integer);
{ Go to location X,Y on playing field. }
VAR Heading : Integer;
BEGIN
LowerShield; {Moving target is hard to hit - so lower shield}
{ Find the heading we need to get to the desired spot. }
Heading := Angle_To(x, y);
{ Keep traveling at top speed until we are within 150 meters }
WHILE (distance(loc_x, loc_y, x, y) > 150) DO Drive(Heading, 100);
{ Cut speed, and creep the rest of the way. }
WHILE (distance(loc_x, loc_y, x, y) > 20) DO Drive(Heading, 20);
{ Stop driving, should coast to a stop. }
Drive(Heading, 0); {I.E., Stop}
RaiseShield; {Still target is easy to hit - so raise shield}
END; {GoTo(X,Y)}
PROCEDURE Aim(VAR Ang : Integer; VAR Arc : Integer);
{
Improve aim by doing a binary search of the target area.
I.E., divide the target area in two equal pieces and redefine
the target area to be the piece where the foe is found.
If the foe is not found, expand the search area to the
maximum arc of plus or minus 10 degrees.
}
BEGIN
Times := 0; { Found enemy -- so set unsuccessful scan count to zero )
Arc := Arc DIV 2; { Divide search area in two. }
IF scan(Ang-Arc, Arc) <> 0 { Check piece "below" target angle. }
THEN Ang := Ang-Arc { If foe found, redefine target angle. }
ELSE IF scan(Ang+Arc, Arc) <> 0 { Check piece "above" target angle. }
THEN Ang := Ang+Arc { If foe found, redefine target angle. }
ELSE Arc := 10;
{ Foe not found in either piece, expand search area to maximum arc. }
END; {Aim}
PROCEDURE Do_Corner;
BEGIN {Do_Corner}
Times := 0; {Count of unsuccessful scans}
Angle := StartAngle[Corner] + 10; {Starting angle for scanning}
REPEAT
Delta := 10; { Start with widest scanning arc. }
Range := scan(Angle, Delta);
WHILE (Range > 40) AND (Range < 700) DO
{ Must be far enough away to avoid self-damage. }
BEGIN
Aim(Angle, Delta); { Improve aim. }
IF ObjectScanned = Enemy THEN cannon(Angle, Range); { Fire!! }
Range := scan(Angle, Delta); { Is foe still in sights? }
END;
Angle := Angle + 20; { Look in adjacent target area. }
IF (Angle > (StartAngle[Corner] + 90))
THEN Angle := StartAngle[Corner] + 10;
Times := Times + 1;
UNTIL Times > 20; { Leave after 20 unsuccessful scans }
END; {Do_Corner}
BEGIN {TagTeam2 Main}
Initialize;
COMM[10] := 0; {Set Ally's corner (if any) to zero}
COMM[11] := 0; {Communicate My corner to Ally}
REPEAT
REPEAT
Corner := Random(3) + 1; {Pick a corner}
UNTIL Corner <> COMM[10]; {Need different corner than Ally}
COMM[11] := Corner; {Communicate My corner to Ally (if any)}
GoTo(CornerX[Corner], CornerY[Corner]);
{ Move to selected corner. }
Do_Corner;
UNTIL Dead OR Winner;
END; {TagTeam2 Main}